package oj;

import java.util.Scanner;

public class Day7F {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int fib1=0;
        int fib2=1;
        int fib3=0;
        int min=0;
        int max=0;
        for (int i = 0; i < 50; i++) {
            fib3=fib1+fib2;
            fib1=fib2;
            fib2=fib3;

            if(a>fib2){
                min=a-fib2;
            }
            if(a<fib3){
                max=fib3-a;
                break;
            }
        }
        System.out.println(Math.min(min,max));

    }
}
